local skel = fk.CreateSkill {
  name = "efengqi__juyi",
  attached_skill_name = "efengqi__juyi_other&",
}

Fk:loadTranslationTable{
  ["efengqi__juyi"] = "聚义",
  [":efengqi__juyi"] = "每轮每种牌名限一次，你可以分配至少两张牌，视为使用一张基本牌；其他角色可以交给你三张同色牌视为使用一张基本牌。",

  ["#efengqi__juyi-use"] = "你可以分配至少两张牌，视为使用一张基本牌",
  ["@$efengqi__juyi"] = "聚义",
  ["#efengqi__juyi-rende"] = "聚义：请分配至少两张牌",

  ["$efengqi__juyi1"] = "同心同德，救困扶危！",
  ["$efengqi__juyi2"] = "施仁布泽，乃我大汉立国之本！",
}

skel:addEffect("viewas", {
  prompt = "#efengqi__juyi-use",
  pattern = ".|.|.|.|.|basic",
  interaction = function (self, player)
    local all_names = player:getTableMark("@$efengqi__juyi")
    local names = player:getViewAsCardNames(self.name, all_names)
    if #names > 0 then
      return UI.CardNameBox { choices = names }
    end
  end,
  card_filter = Util.FalseFunc,
  view_as = function (self, player, cards)
    if Fk.all_card_types[self.interaction.data] == nil then return nil end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = self.name
    return card
  end,
  before_use = function(self, player, use)
    local room = player.room
    local mark = table.filter(player:getTableMark("@$efengqi__juyi"), function (name)
      return Fk:cloneCard(name).trueName ~= use.card.trueName
    end)
    room:setPlayerMark(player, "@$efengqi__juyi", #mark > 0 and mark or 0)
    room:askToYiji(player, {
      cards = player:getCardIds("he"), targets = room:getOtherPlayers(player, false), skill_name = skel.name,
      min_num = 2, max_num = 9999, prompt = "#efengqi__juyi-rende", cancelable = false,
    })
  end,
  enabled_at_play = function(self, player)
    return #player:getCardIds("he") > 1
    and table.find(Fk:currentRoom().alive_players, function (p) return p ~= player end)
  end,
  enabled_at_response = function(self, player, response)
    return not response and #player:getCardIds("he") > 1
    and table.find(Fk:currentRoom().alive_players, function (p) return p ~= player end)
    and Fk.currentResponsePattern and table.find(player:getTableMark("@$efengqi__juyi"), function (name)
      return Exppattern:Parse(Fk.currentResponsePattern):matchExp(".|.|.|.|" .. name) -- 注意，标记里存的是name而非trueName
    end)
  end,
})

skel:addEffect(fk.RoundStart, {
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(skel.name, true)
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@$efengqi__juyi", Fk:getAllCardNames("b"))
  end,
})

skel:addAcquireEffect(function (self, player, is_start)
  player.room:setPlayerMark(player, "@$efengqi__juyi", Fk:getAllCardNames("b"))
end)

skel:addLoseEffect(function (self, player, is_death)
  player.room:setPlayerMark(player, "@$efengqi__juyi", 0)
end)

return skel
